package ink.ykb.redisLockDemo.config.lock.redis;

import java.io.UnsupportedEncodingException;

import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class LockRedisChannelListener implements MessageListener{

	public void onMessage(Message message, byte[] pattern) {
		byte[] channel = message.getChannel();
		byte[] bs = message.getBody();
		try {
			String cha = new String(channel,"UTF-8");
			String content = new String(bs,"UTF-8");
			log.info("频道：{}，消息：{}",cha,content);
			Object lockObject = RedisLockAopConf.lockObjectMap.get(cha);
			if(lockObject != null) {
				synchronized (lockObject) {
					lockObject.notify();
				}
			}
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
			
	}

}
